﻿@model PaginationModel

<div class="pull-right" >
    <ul class="pagination" style="margin:0px;">
        @foreach (var link in Model.PaginationLinks)
        {
            @BuildLink(link)
        }
    </ul>
</div>





@helper BuildLink(PaginationLink link)
{
	var liBuilder = new TagBuilder("li");
	if (link.IsCurrent)
	{
		liBuilder.MergeAttribute("class", "active");
	}
	if (! link.Active)
	{
		liBuilder.MergeAttribute("class", "disabled");
	}
	
	var aBuilder = new TagBuilder("a");
	if (link.Url == null)
    {
        aBuilder.MergeAttribute("href", "javascrpt:void(0)");
	}
	else
	{
		aBuilder.MergeAttribute("href", link.Url);
	}
	
	// Ajax support
	if (Model.AjaxOptions != null)
        {
            foreach (var ajaxOption in Model.AjaxOptions.ToUnobtrusiveHtmlAttributes())
            {
                aBuilder.MergeAttribute(ajaxOption.Key, ajaxOption.Value.ToString(), true);
            }
        }
    //if (link.DisplayText == "«")
    //{
    //    aBuilder.SetInnerText("←");
    //}
    //else if (link.DisplayText == "»")
    //{
    //    aBuilder.SetInnerText("→");
    //}
    //else
    //{
		aBuilder.SetInnerText(link.DisplayText);		
	//}
	liBuilder.InnerHtml = aBuilder.ToString();
	
	@Html.Raw(liBuilder.ToString())
}
